#ifndef GROUPCONFIGVIEW_H
#define GROUPCONFIGVIEW_H

#include ".\configview\configview.h"
#include <QMap>
#include <QPair>
#include <QJsonArray>
#include <QtMath>

class QGroupBox;
class QScrollArea;
class QButtonGroup;

class GroupConfigView : public ConfigView
{
    Q_OBJECT
public:
    explicit GroupConfigView(QObject *parent = nullptr);
    ~GroupConfigView();

    QWidget* viewWidget() override;
    void updateConfig(const QJsonArray &config) override;
    QJsonArray getModifiedConfig() const override;
    void applyEdits() override;
    void resetToOriginal() override;

private:
    void clearView();
    QWidget* createEditableWidget(const QString &key, const QJsonValue &value,
                                 int configIndex, int itemIndex = -1);
    QJsonValue getValueFromWidget(QWidget *widget) const;

private slots:
    void handleModeButtonClicked(QAbstractButton *button);
    void handleAdcChannelMove(bool up, int configIndex, int channelIndex);
    void handleAdcChannelEdit(const QString &text, int configIndex, int channelIndex);

signals:
    void sig_sendConfigData(QJsonArray config_data);
private:
    QWidget *m_view = nullptr;
    QScrollArea *m_scrollArea = nullptr;
    QWidget *m_scrollContent = nullptr;
    QJsonArray m_currentConfig;
    QJsonArray m_originalConfig;
    QMap<QWidget*, QPair<int, QPair<int, QString>>> m_editWidgets;
};

#endif // GROUPCONFIGVIEW_H
